<?php

/**
 *	  资金流向：收入
 *    支出类型：取消订单, 针对不是通过预存款支付的订单的取消订单资金处理(返回给买家支付的金额), 必须是已付款的订单, 该接口不考虑退款的订单
 *
 *	  该接口目前尚无使用，使用时请增加
 *    1)语言包 'cancelorder' => '卖家取消订单'
 *	  2)在 app/seller_order.app.php 的 function cancel_order() 下增加
 		
		// 针对不是通过预存款支付的订单的取消订单资金处理(返回给买家支付的金额),必须是已付款的订单 
		if(in_array($order_info[$id]['status'], array(20, 30)) && in_array($order_info[$id]['payment_code'], array('alipay')))
		{
			// 转到对应的业务实例，不同的业务实例用不同的文件处理，如购物，卖出商品，充值，提现等，每个业务实例又继承支出或者收入
			$depopay_type    =&  dpt('income', 'cancelorder');
			$result  		 = $depopay_type->submit(array(
				'trade_info' =>  array('user_id'=>$order_info[$id]['buyer_id'], 'party_id'=>0, 'amount'=>$order_info[$id]['order_amount']),
				'extra_info' =>  $order_info[$id],
				'post'		 =>	 $_POST,
			));
		}
		
 
 *    @author   psmb
 *    @usage    none
 */
class CancelorderIncome extends IncomeDepopay
{
    var $_purpose_name = 'cancelorder';
	
	// 实际推荐人级数
	var $_layer; 
	
	// 推荐人数组
	var $_referee_list = array();
	
	/* 推荐人获取佣金比例数组 */
	var $_rate;

	function submit($data)
	{
		/* 释放trade_info和extra_info和post三个变量 */
        extract($data);
        /* 处理交易基本信息 */
        $base_info = $this->_handle_trade_info($trade_info, $post);
		if (!$base_info)
        {
            /* 基本信息验证不通过 */
            return false;
        }

		if(!$this->_insert_record_info($trade_info, $extra_info)) {
			$this->_errorCode[] = "50023";
			return false;
		}
		
				
		return true;
	}
	
	

	/* 插入收支记录，并变更账户余额 */
	function _insert_record_info($trade_info, $extra_info)
	{
		$time = gmtime();
		
		// 增加用户的收支记录
		$data_record = array();
		$data_record['tradesn'] =   $this->_gen_trade_sn();
		$data_record['user_id']	=	$trade_info['user_id'];
		$data_record['party_id']=	0;
		$data_record['amount']  =   $trade_info['amount'];
		$data_record['balance']	=	$this->_get_deposit_balance($trade_info['user_id'], $trade_info['amount']); // 增加后的余额
		$data_record['flow']	=	$this->_flow_name;
		$data_record['purpose']	=	$this->_purpose_name;
		$data_record['payway']  =   $extra_info['seller_name'];
		$data_record['name']    =   Lang::get($this->_purpose_name);
		$data_record['status']  = 	'SUCCESS';
		$data_record['add_time']=   $time;
		$data_record['pay_time']=   $time;
		$data_record['end_time']=   $time;
		
		/* 插入用户的收支记录 */
		return parent::_insert_deposit_record($data_record);
	}
	
}

?>
